using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Controls;

namespace PlanetWPF.Toolbelt.Utils
{
    public static class PowerUX
    {
        /// <summary>
        /// Private Attached <see cref="DependencyProperty"/> that tracks if an element is being dragged.
        /// </summary>
        private static readonly DependencyProperty IsDraggingProperty;

        /// <summary>
        /// Attached <see cref="DependencyProperty"/> that allows items within a Canvas to be dragged around.
        /// </summary>
        public static readonly DependencyProperty ContentsDraggableProperty;

        static PowerUX()
        {
            //Register IsDraggingProperty
            IsDraggingProperty = DependencyProperty.RegisterAttached(
                "IsDragging",
                typeof(Boolean),
                typeof(PowerUX));
            //Register ContentsDraggableProperty
            ContentsDraggableProperty = DependencyProperty.RegisterAttached(
                "ContentsDraggable",
                typeof(bool),
                typeof(PowerUX),
                new FrameworkPropertyMetadata(
                    new PropertyChangedCallback(OnSetContentsDraggable)));
        }

        public static bool GetContentsDraggable(DependencyObject obj)
        {
            return (bool)obj.GetValue(ContentsDraggableProperty);
        }

        public static void SetContentsDraggable(DependencyObject obj, bool value)
        {
            obj.SetValue(ContentsDraggableProperty, value);
        }



        private static Boolean GetIsDragging(DependencyObject obj)
        {
            return (Boolean)obj.GetValue(IsDraggingProperty);
        }

        private static void SetIsDragging(DependencyObject obj, Boolean value)
        {
            obj.SetValue(IsDraggingProperty, value);
        }





        private static void OnSetContentsDraggable(DependencyObject sender, DependencyPropertyChangedEventArgs args)
        {
            Canvas target = sender as Canvas;
            if (target == null)
            {
                throw new InvalidOperationException("ContentsDraggable can only be set on an Element that derives from Canvas.");
            }
            else
            {
                target.PreviewMouseLeftButtonDown += new System.Windows.Input.MouseButtonEventHandler(DraggableMouseDown);
                target.PreviewMouseMove += new System.Windows.Input.MouseEventHandler(DraggableMouseMove);
                target.PreviewMouseLeftButtonUp += new System.Windows.Input.MouseButtonEventHandler(DraggableMouseUp);
            }
        }

        private static void DraggableMouseUp(object sender, System.Windows.Input.MouseButtonEventArgs e)
        {
            throw new Exception("The method or operation is not implemented.");
        }

        private static void DraggableMouseMove(object sender, System.Windows.Input.MouseEventArgs e)
        {
            throw new Exception("The method or operation is not implemented.");
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private static void DraggableMouseDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
        {

        }
    }
}
